package com.dodo.blog.ui.component.composite;

import com.dodo.blog.WebApplication;
import com.dodo.blog.model.Account;
import com.dodo.blog.ui.component.container.Panel;
import com.dodo.blog.ui.component.input.Anchor;
import com.dodo.blog.ui.component.simple.Span;
import com.dodo.blog.ui.page.publish.Login;
import com.dodo.blog.ui.page.publish.MyAccount;
import com.dodo.blog.ui.page.publish.Registration;

import static com.dodo.blog.ui.util.Localization.localize;

/**
 * @author <a href="mailto:pohorelec@comvai.com">Jozef Pohorelec</a>
 */
public class UserInfoPanel
        extends Panel
{
    public UserInfoPanel()
    {
        setClassName( "user-info-panel" );

        WebApplication webApplication = WebApplication.get();
        Account account = webApplication.getLoggedInAccount();
        if ( account != null )
        {
            Anchor link = new Anchor( account.getUserInfo(), MyAccount.class );
            add( link );
        }
        else
        {
            add( new Span( localize(
                    "label.registerOrLogin",
                    webApplication.getPathByPageClass( Registration.class ),
                    webApplication.getPathByPageClass( Login.class ) ) ) );
        }
    }
}
